import Flutter
import UIKit

public class SwiftBragePlugin: NSObject, FlutterPlugin {
    public static func register(with registrar: FlutterPluginRegistrar) {
        let channel = FlutterMethodChannel(name: "brage", binaryMessenger: registrar.messenger())
        let instance = SwiftBragePlugin()
        registrar.addMethodCallDelegate(instance, channel: channel)
    }
    
    public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
        if(call.method == "getPlatformVersion"){
            result("iOS " + UIDevice.current.systemVersion)
        }else if(call.method == "setIOSBrage"){
            if #available(iOS 8.0, *) {
                let userSettings = UIUserNotificationSettings(types:[
                    .badge,
                    .sound,
                    .alert],
                                                              categories:nil)
                UIApplication.shared.registerUserNotificationSettings(userSettings)
                UIApplication.shared.applicationIconBadgeNumber = call.arguments as! Int
            } else {
                UIApplication.shared.applicationIconBadgeNumber = call.arguments as! Int
            }
        }
        else{
            result("iOS no found action")
        }
    }
}
